<html>
<head><meta charset="utf-8"><title>Box&lt;_&gt; API  - add replace() and take() methods? · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Box.3C_.3E.20API.20.20-.20add.20replace().20and.20take().20methods.3F.html">Box&lt;_&gt; API  - add replace() and take() methods?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207320396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Box%3C_%3E%20API%20%20-%20add%20replace%28%29%20and%20take%28%29%20methods%3F/near/207320396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim McNamara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Box.3C_.3E.20API.20.20-.20add.20replace().20and.20take().20methods.3F.html#207320396">(Aug 18 2020 at 21:46)</a>:</h4>
<p>The <code>std::mem::replace()</code> and <code>std::mem::take()</code> methods are quite handy when interacting with boxes. In my opinion, we could extend the API to make things more comfortable to use.</p>
<p>This idea was suggested ~5 years ago and rejected (<a href="https://github.com/rust-lang/rust/issues/23309">https://github.com/rust-lang/rust/issues/23309</a>). Perhaps it could be re-considered?</p>



<a name="207353522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Box%3C_%3E%20API%20%20-%20add%20replace%28%29%20and%20take%28%29%20methods%3F/near/207353522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Box.3C_.3E.20API.20.20-.20add.20replace().20and.20take().20methods.3F.html#207353522">(Aug 18 2020 at 23:10)</a>:</h4>
<p>they'd need to be associated functions, and <code>Box::replace(&amp;mut b, val)</code> doesn't seem any obviously better than <code>replace(&amp;mut b, val)</code></p>



<a name="207364650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Box%3C_%3E%20API%20%20-%20add%20replace%28%29%20and%20take%28%29%20methods%3F/near/207364650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim McNamara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Box.3C_.3E.20API.20.20-.20add.20replace().20and.20take().20methods.3F.html#207364650">(Aug 19 2020 at 02:38)</a>:</h4>
<p>Ah that makes sense. I agree that there's no obvious benefit there. I was hoping that it would be possible to align the APIs of Cell and Box slightly.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>